#include "gtest/gtest.h"
#include <iostream> 
#include <memory>

#include "IStream.h"

using namespace streamdb;
//For Use rocksdb::LRUCache
//template<typename K>
//struct CacheNode {
//    static const int defaultCacheBlockSize = 1024;
//
//    CacheNode<K> * prev;
//    CacheNode<K> * next;
//    int used;
//    const int blockSize;
//    void * data;
//    K key;
//
//    CacheNode(size_t blockSize = defaultCacheBlockSize, void * data=nullptr) : prev(nullptr), next(nullptr), key(0),used(0), blockSize(blockSize),data(data){}
//    ~CacheNode(){
//    }
//    size_t free(){
//        return 0;
//    }
//    void insertTail(const std::string & msg){
//    }
//    void insert(uint64_t offset, const std::string & msg){
//    }
//}; 
//
//
//
////Cache Value->Block 
//class Block {
//public:
//    bool append(const rocksdb::Slice msg);
//    bool insert(uint64_t offset, const rocksdb::Slice msg);
//    rocksdb::Slice lookup(uint64_t offset);
//    void erase(uint64_t offset);
//
//    size_t freeBytes() const;
//    size_t used() const;
//    size_t capacity() const;
//private:
//    size_t waterMark;
//};


class StreamAppender {
public:
    static std::unique_ptr<StreamAppender> make(std::shared_ptr<IStream> & s) {
        return std::move(std::unique_ptr<StreamAppender>(new StreamAppender(s)));
    }
    StreamAppender(std::shared_ptr<IStream> & s)
    : s(s)
    {
        s->open();
    }

    virtual ~StreamAppender(){
    }

    Status append(const rocksdb::Slice & msg) {
        return s->append(msg);
    }
private:
    std::shared_ptr<IStream> s;
};



TEST(StreamAppenderTest, use){

    std::shared_ptr<IStream> s = makeStream("StreamAppenderTest.stream");
    std::unique_ptr<StreamAppender> appender = StreamAppender::make(s);
    appender->append("gtp,string");
    appender->append("gtp,string2");

//class StreamReader {
//public:
//};
//    {
//        std::unique_ptr<StreamReader> reader = makeReaderFromStream(&s);
//        auto iter = readr->seek(offset);
//        while(iter->hasNext()){
//            std::cout << iter->next() << std::endl;
//        }
//    }
//
//    {
//        std::unique_ptr<Reader> reader = makeReaderFromStream(&cs);
//        auto iter = readr->seek(offset);
//        while(iter->hasNext()){
//            std::cout << iter->next() << std::endl;
//        }
//    }
}
